//
//  ZLAlert+ZLContent.m
//  ZLAlert-OC
//
//  Created by 科大 on 2024/1/2.
//

#import "ZLAlert+ZLContent.h"

@implementation ZLAlert (ZLContent)

- (ZLAlert *)addContent:(NSString *)content {
    return [self addContent:content config:ZLAlertConfig.shared.contentConfig];
}

- (ZLAlert *)addContent:(NSString *)content config:(ZLAlertItemConfig *)config {
    UIView *lastView = self.mainView.subviews.lastObject;
    
    UILabel *label = [UILabel zl_labelWithConfig:config];
    label.text = content;
    label.font = config.font;
    label.textColor = config.color;
    label.textAlignment = config.alignment;
    label.backgroundColor = config.backgroundColor;
    label.layer.cornerRadius = config.cornerRadius;
    label.layer.borderWidth = config.borderWidth;
    label.layer.borderColor = config.borderColor.CGColor;
    label.numberOfLines = 0;
    
    [self.mainView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mainView).offset(config.insets.left);
        make.right.equalTo(self.mainView).offset(-config.insets.right);
        
        if (lastView == nil) {
            make.top.equalTo(self.mainView).offset(config.insets.top);
        } else {
            make.top.equalTo(lastView.mas_bottom).offset(config.insets.top);
        }
    }];
    
    return [self layoutMainView:20];
}

@end
